import java.sql.SQLOutput;//fixwell    
import java.util.Random;
import java.util.Scanner;
public class Manager {
    public static void main(String[] args) {
         boolean enter=true;
        while (enter) {
            Scanner sc = new Scanner(System.in);
            System.out.println("--------------------------------------------------------------");
            System.out.println("                      欢迎使用密码管理系统");
            System.out.println("--------------------------------------------------------------");
            System.out.print("请选择操作：\n" +
                    "1. 加密\n" +
                    "2. 解密\n" +
                    "3. 判断密码强度（第三周任务添加）\n" +
                    "4. 密码生成（第三周任务添加）\n" +
                    "5. 退出\n" +
                    "请输入选项序号：");
            int number = sc.nextInt();
            if (number == 1) {
                try {
                    Task1 t1 = new Task1();
                    t1.print();
                } catch (Exception e) {
                    System.out.println("输入的格式错误");
                }

            }
            if (number == 2) {
                try {
                    Task2 t2 = new Task2();
                    t2.print();
                } catch (Exception e) {
                    System.out.println("输入的字符错误");
                }
            }
            if (number == 3) {
                try {
                    Task3 t3 = new Task3();
                    t3.adjust();
                } catch (Exception e) {
                    System.out.println("输入的格式错误");
                }
            }
            if (number == 4) {
                try {
                    Task4 t4 = new Task4();
                    System.out.println("生成的密码是:"+t4.buildpassword());
                } catch (Exception e) {
                    System.out.println("输入的长度错误");
                }
            }
            if (number == 5) {
                enter = false;
            }
        }
    }
    }
class Task1{
    Scanner sc=new Scanner(System.in);
    int[]change;
    char[] charpassword;
    String password;
    String regrex;
 public Task1() throws Exception {
     System.out.print("请输入要加密的数字密码(不超过16位)：");
     password=sc.next();
     regrex="\\S{1,16}";
     if (!password.matches(regrex)){
         throw new Exception();
     }
     charpassword=password.toCharArray();
     charpassword[password.length()-1]=password.charAt(0);
     charpassword[0]=password.charAt(password.length()-1);
     change=new int[password.length()];
     for (int i=0;i<password.length();i++){
         change[i]=charpassword[i]+3;
     }
     for (int i=0;i< change.length;i++){
         charpassword[i]=(char)(change[i]);
     }
     password=new String(charpassword);
}
public void print(){
     System.out.print("加密后的结果是："+password);
    System.out.println("");}
}
class Task2{
    Scanner sc=new Scanner(System.in);
    int[]change;
    char[] charpassword;
    String password;
    String regrex;
    public Task2()throws Exception{
     System.out.print("请输入要解密的数字密码(不超过16位)：");
    password=sc.next();
    regrex="\\S{1,16}";
if (!password.matches(regrex)){
    throw new Exception();
}
    charpassword=password.toCharArray();
    charpassword[password.length()-1]=password.charAt(0);
    charpassword[0]=password.charAt(password.length()-1);
    change=new int[password.length()];
     for (int i=0;i<password.length();i++){
        change[i]=charpassword[i]-3;
    }
     for (int i=0;i< change.length;i++){
        charpassword[i]=(char)(change[i]);
    }
    password=new String(charpassword);

}
    public void print(){
    System.out.print("解密后的结果是："+password);
    System.out.println("");}
}
class Task3 {
    Scanner sc = new Scanner(System.in);
    String password;
    int[]change;
    char[] charpassword;
    int test;
    public Task3() {
        System.out.print("请输入你的密码：");
        password = sc.next();
        charpassword=password.toCharArray();
        test=0;
    }
    public void adjust() throws Exception{
        charpassword = password.toCharArray();
        change = new int[charpassword.length];
        for (int i = 0; i < charpassword.length; i++) {
            change[i] = (int)charpassword[i];
            if (test == 0) {
                if (change[i] <= 57 && change[i] >= 48) {
                    test++;
                } else if (change[i] <= 90 && change[i] >= 65) {
                    test = test + 2;
                } else if (change[i] <= 122 && change[i] >= 97) {
                    test = test + 3;
                }
            } else if (test == 1) {
                if (change[i] <= 90 && change[i] >= 65) {
                    test = test + 20;
                } else if (change[i] <= 122 && change[i] >= 97) {
                    test = test + 30;
                }
            } else if (test == 2) {
                if (change[i] <= 57 && change[i] >= 48) {
                    test = test + 10;
                } else if (change[i] <= 122 && change[i] >= 97) {
                    test = test + 30;
                }
            } else if (test == 3) {
                if (change[i] <= 57 && change[i] >= 48) {
                    test = test + 10;
                } else if (change[i] <= 90 && change[i] >= 65) {
                    test = test + 20;
                }
            } else if (test == 21 || test == 12) {
                if (change[i] <= 122 && change[i] >= 97) {
                    test = test + 100;
                }
            } else if (test == 23 || test == 32) {
                if (change[i] <= 57 && change[i] >= 48) {
                    test = test + 100;
                } else if (test == 13 || test == 31) {
                    if (change[i] <= 90 && change[i] >= 65) {
                    test = test + 100;
                    }
                }
                if(charpassword.length>16||charpassword.length<0){
                    throw new Exception();
                }
            }
        }
        if (charpassword.length < 8 ||(test<10&&test>0)) {
            System.out.println("弱强度");
        }
        else if(charpassword.length>=8&&test<100&&test>10){
            System.out.println("中强度");
        }
        else if(charpassword.length>=8&&test>100){
            System.out.println("高强度");
        }
    }
}
class Task4 {
    Random rd;
    Scanner sc;
    int length;
    int egword;
    int proegword;
    int mathword;
    int testnumber0;
    int testnumber1;
    int testnumber2;
    int testnumber;
    char[] changepassword;
    String password;
    public Task4() {
        System.out.print("请输入你的密码长度:");
        sc = new Scanner(System.in);
        length = sc.nextInt();
        rd = new Random();
    }
    public String buildpassword() throws Exception{
        if (length < 8&&length>0) {
            changepassword = new char[length];
            testnumber = rd.nextInt(3);
            if (testnumber == 0) {
                for (int i = 0; i < length; i++) {
                    mathword = rd.nextInt(10) + 48;
                    changepassword[i] = (char) mathword;
                }
                password=new String(changepassword);
            } else if (testnumber == 1) {
                for (int i = 0; i < length; i++) {
                    egword = rd.nextInt(26) + 97;
                    changepassword[i] = (char) egword;
                }
                password=new String(changepassword);
            } else if (testnumber == 2) {
                for (int i = 0; i < length; i++) {
                    proegword = rd.nextInt(26) + 65;
                    changepassword[i] = (char) proegword;
                }
                password=new String(changepassword);
            }
            return password;
        }
        else if (length<0||length>16){
            throw new Exception();
        }
        else {
            changepassword = new char[length];
            testnumber0 = 0;
            testnumber1 = 0;
            testnumber2 = 0;
            for (int i = 0; i < length; i++) {
                testnumber = rd.nextInt(3);
                if (testnumber == 0) {
                    mathword = rd.nextInt(10) + 48;
                    changepassword[i] = (char) mathword;
                    testnumber0++;
                }
                if (testnumber == 1) {
                    egword = rd.nextInt(26) + 97;
                    changepassword[i] = (char) egword;
                    testnumber1++;
                }
                if (testnumber == 2) {
                    proegword = rd.nextInt(26) + 65;
                    changepassword[i] = (char) proegword;
                    testnumber2++;
                }
            }
            password=new String(changepassword);
            if (testnumber0 != 0 && testnumber1 != 0 && testnumber2 != 0) {
                return password;
            } else {
                return buildpassword();
            }
        }
    }
}